//
//  JrdMyLearnViewController.m
//  v2ex-iOS
//
//  Created by longcheng on 16/5/20.
//  Copyright © 2016年 Singro. All rights reserved.
//

#import "JrdMyLearnViewController.h"
#import "SCBarButtonItem.h"
#import "SDCycleScrollView.h"
#import "JrdCommon.h"
#import "JRDCourseCell.h"
#import "UIView+MJExtension.h"
#import "MJRefresh.h"
#import "JRDCourseDetail.h"
#import "JrdCourseDetailViewController.h"
#import "MusicModel.h"
#import "JrdSearchViewController.h"
#import "CKHttpCommunicate.h"
#import "JrdCourseModel.h"
#import "JZCateModel.h"
#import "JrdTabCommonController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "LiuXSegmentView.h"
#import "JrdChapterViewController.h"
#import "LCCSqliteManager.h"
#import "JrdDatamanager.h"
#import "CKHttpCommunicate.h"
#import "JrdSelCourseModel.h"
@interface JrdMyLearnViewController ()<UITableViewDataSource,UITableViewDelegate>{
    //define the array
    NSMutableArray *courseSeletedArray;
    NSMutableArray *courseSelectArray;
    NSInteger _type;/**< segment */
    NSInteger _page;/**< 页数 */
    NSInteger _limit;/**< 每页的个数 */
    NSInteger _charge;/**< 1：免费；2：收费 */
    LCCSqliteManager* manager;
    NSArray* courseSel;

}

@property (nonatomic, strong) SCBarButtonItem *leftBarItem;
@property (nonatomic, strong) SCBarButtonItem *rightBarItemExpend;
@property (nonatomic, strong) SDCycleScrollView* cycleScrollView;
@property (nonatomic, strong) UIView *section_view;
@property(nonatomic, strong) UITableView *tableView;

//Fake Data
@property (nonatomic, strong) NSMutableArray *songArray;
@end

@implementation JrdMyLearnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sc_navigationItem.leftBarButtonItem = self.leftBarItem;
    self.sc_navigationItem.rightBarButtonItem = self.rightBarItemExpend;
    courseSel = [[NSMutableArray alloc] init];
    // Do any additional setup after loading the view.
    manager = [LCCSqliteManager shareInstance];
    [manager openSqliteFile:@"database"];

    [self initData];
    NSString * searchCondition = [NSString stringWithFormat:@"is_select=%@ and user_id=%@",
                                  @(1),[JrdDatamanager manager].user.userId];
    courseSel= [manager searchDataFromSheet:@"courselist" where:searchCondition];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reloadDataUpdate)
                                                 name:kSelectCourseNotification
                                               object:nil];

}
- (void)reloadDataUpdate{
    NSString * searchCondition = [NSString stringWithFormat:@"is_select=%@ and user_id=%@",
                                  @(1),[JrdDatamanager manager].user.userId];
    courseSel= [manager searchDataFromSheet:@"courselist" where:searchCondition];
    [self.tableView reloadData];
}
- (void)initData{
    _type = 0;
    _page = 1;
    _limit = 20;
    _charge = 1;
}

- (void)viewDidAppear:(BOOL)animated{

    self.sc_navigationItem.title = NSLocalizedString(@"v2_my_study",nil);//@"我们学习";
    self.sc_navigationBar.backgroundColor = JrdNavigationBarColor;
}

- (void)viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reloadData)
                                                 name:kReloadDataNotification
                                               object:nil];
}

- (void)reloadData{
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadView{
    NSLog(@"zlwu,--------loadView--------");
    [super loadView];
    [self configureNavibarItems];
    [self configureImageView];
    [self configureSegmentView];
    [self configureTable];
}



#pragma mark - Navigation
- (void)configureNavibarItems {
    
    self.leftBarItem = [[SCBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ico-menu"] highlight:[UIImage imageNamed:@"ico-menu"] style:SCBarButtonItemStylePlain handler:^(id sender) {
        [[NSNotificationCenter defaultCenter] postNotificationName:kShowMenuNotification object:nil];
    }];
    /*self.rightBarItemExpend = [[SCBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ico-search"] style:SCBarButtonItemStylePlain handler:^(id sender) {
        NSLog(@"Click the search icon");
        //Go to search screen
        JrdSearchViewController* searchScreen = [[JrdSearchViewController alloc] init];
        [self.navigationController pushViewController:searchScreen animated:YES];
    }];*/
}

#pragma mark - cycleScrollView
- (void)configureImageView{
    

    NSArray* imageArray = @[@"MyLearning_Ad_1.jpg",@"MyLearning_Ad_1.jpg",@"MyLearning_Ad_1.jpg",@"MyLearning_Ad_1.jpg"];
    BOOL is_iphone_6 = false;
    float max_length = MAX(SCREEN_WIDTH, SCREEN_HEIGHT);
    if(max_length == 736.0){
        is_iphone_6 = true;
    }
    if(true == is_iphone_6){
        self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT+STATUS_BAR_HEIGHT, SCREEN_WIDTH, 250) imageURLStringsGroup:nil];
    }else{
        self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT+STATUS_BAR_HEIGHT, SCREEN_WIDTH, JRD_CYCLE_SCROLL_H) imageURLStringsGroup:nil];
    }
    self.cycleScrollView.placeholderImage = [UIImage imageNamed:@"MyLearning_Ad_1.jpg"];
    
    self.cycleScrollView.autoScrollTimeInterval = 3.0;
    self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    [self.view addSubview:self.cycleScrollView];
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [CKHttpCommunicate createRequest:HTTP_GET_PHOTO WithParam:nil withMethod:GET success:^(id result) {
            NSMutableArray* imageArrayUrl = [[NSMutableArray alloc] init];

            if (result) {
                NSArray* resultArray = (NSArray*)result;
                for(int i = 0; i < resultArray.count; i++){
                    NSString* imagePath = [NSString stringWithFormat:@"http://120.55.86.220/%@",[resultArray[i] valueForKey:@"image_path"]];
                    [imageArrayUrl addObject:imagePath];
                }
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                self.cycleScrollView.imageURLStringsGroup = (NSArray*)imageArrayUrl;
            });
        }failure:^(NSError *erro) {
            
        } showHUD:nil];
    });
}

#pragma mark - segment View
- (void)configureSegmentView{
    int view_y = 0;
    view_y = _cycleScrollView.frame.origin.y + _cycleScrollView.bounds.size.height;
    _section_view = [[UIView alloc] initWithFrame:CGRectMake(0, view_y, SCREEN_WIDTH, STUDY_VIEW_SECTION_H)];
    [_section_view setBackgroundColor:JrdNavigationBarColor];//JRD_RGB(67, 199, 176)];
    [self.view addSubview:_section_view];
}

- (void)tagClick:(NSInteger)index{
    //do nothing
    _type = index;
    
    if((1 == _type && nil == courseSelectArray)){
        [self.tableView.mj_header beginRefreshing];
        [self loadNewData];
    }else{
        [self.tableView reloadData];
    }
    
    if(2 == _type && nil == courseSeletedArray){
        [self.tableView.mj_header beginRefreshing];
        [self loadNewData];
    }else{
        [self.tableView reloadData];
    }
}


#pragma mark - fake data
- (void)getCourseData{
    /*NSDictionary *parameter;
    parameter =@{
                 @"userid":[JrdDatamanager manager].user.userId
                 };
    __weak typeof(self) weakself = self;
    [CKHttpCommunicate createRequest:HTTP_COURSE_DATA WithParam:parameter withMethod:GET success:^(id result) {
        if (result) {
            NSMutableArray *CourseSelListArray = [result objectForKey:@"SelectedCourses:"];
            for(int i = 0; i < CourseSelListArray.count; i++){
                NSArray* model = [CourseSelListArray objectAtIndex:i];
                //[courseSel addObject:model];
                //insert data into sql
                NSString * searchCondition = [NSString stringWithFormat:@"course_id=%@ and user_id=%@",[model valueForKey:@"course_id"],[JrdDatamanager manager].user.userId];
                NSArray* array = [manager searchDataFromSheet:@"courselist" where:searchCondition];
            }
            [weakself.tableView reloadData];
            [weakself.tableView.mj_header endRefreshing];
            [weakself.tableView.mj_footer endRefreshing];
        }
    } failure:^(NSError *erro) {
        
    } showHUD:nil];
     */    NSDictionary *parameter;
    parameter =@{
                 @"userid":[JrdDatamanager manager].user.userId
                 };
    __weak typeof(self) weakself = self;
    [CKHttpCommunicate createRequest:HTTP_COURSE_DATA WithParam:parameter withMethod:GET success:^(id result) {
        if (result) {
            NSMutableArray* course_sel = [[NSMutableArray alloc] init];
            NSMutableArray* courseAva = [[NSMutableArray alloc] init];

            [course_sel removeAllObjects];
            [courseAva removeAllObjects];
            NSMutableArray *CourseSelListArray = [result objectForKey:@"SelectedCourses:"];
            for(int i = 0; i < CourseSelListArray.count; i++){
                JrdSelCourseModel* model = [[JrdSelCourseModel alloc] init];
                model.course_name = [[CourseSelListArray objectAtIndex:i] valueForKey:@"course"];//category_id
                model.category_id = [[CourseSelListArray objectAtIndex:i] valueForKey:@"category_id"];//category_id
                model.startDate =[[CourseSelListArray objectAtIndex:i] valueForKey:@"startDate"];
                model.endDate = [[CourseSelListArray objectAtIndex:i] valueForKey:@"endDate"];
                [course_sel addObject:model];
            }
            
            NSMutableArray *CourseAvaListArray = [result objectForKey:@"AvailableCourses:"];
            NSMutableArray* avaArray = [[NSMutableArray alloc] init];
            NSString* preModelCategory;
            for(int i = 0; i < CourseAvaListArray.count; i++){
                NSDictionary* array_get=[CourseAvaListArray objectAtIndex:i];
                NSMutableDictionary* array = [NSMutableDictionary dictionaryWithDictionary:array_get];
                NSString* currentCategory = [array valueForKey:@"category"];
                
                NSDictionary* startDic = [NSDictionary dictionaryWithObject:@"" forKey:@"startDate"];
                NSDictionary* endDic = [NSDictionary dictionaryWithObject:@"" forKey:@"endDate"];
                [array addEntriesFromDictionary:startDic];
                [array addEntriesFromDictionary:endDic];
                
                for(int i = 0; i < course_sel.count; i++){
                    JrdSelCourseModel* model = course_sel[i];//[[JrdSelCourseModel alloc] init];
                    if([model.course_name isEqualToString:[array valueForKey:@"course"]] && [model.category_id isEqualToString:[array valueForKey:@"category_id"]]){
                        //NSDictionary* startDic = [NSDictionary dictionaryWithObject:model.startDate forKey:@"startDate"];
                        //NSDictionary* endDic = [NSDictionary dictionaryWithObject:model.endDate forKey:@"endDate"];
                        [array setValue:model.startDate forKey:@"startDate"];
                        [array setValue:model.endDate forKey:@"endDate"];
                        break;
                    }
                }
                
                if(nil == preModelCategory || ![preModelCategory isEqualToString:currentCategory]){
                    preModelCategory = currentCategory;//model.courseCategory;
                    avaArray = [[NSMutableArray alloc] init];
                    
                    [avaArray addObject:array];
                    //[courseAva addObject:avaArray];
                }else{
                    [avaArray addObject:array];
                }
                
                
                NSString* startDate_v  = @"";
                NSString* endDate_v = @"";
                NSString * searchCondition = [NSString stringWithFormat:@"course_id=%@ and user_id=%@",[CourseAvaListArray[i] valueForKey:@"course_id"],[JrdDatamanager manager].user.userId];
                NSArray* arraySearch = [manager searchDataFromSheet:@"courselist" where:searchCondition];
                NSString* course_name =[array valueForKey:@"course"];
                NSString* category = [array valueForKey:@"category_id"];
                for(int i = 0; i < course_sel.count; i++){
                    JrdSelCourseModel* model = course_sel[i];//[[JrdSelCourseModel alloc] init];
                    if([model.course_name isEqualToString:course_name] && [model.category_id isEqualToString:category]){
                        startDate_v = model.startDate;
                        endDate_v = model.endDate;
                        break;
                    }
                }
                
                if(nil == arraySearch|| 0 == arraySearch.count){
                    Boolean ret = [manager insertDataToSheet:@"courselist" withData:@[
                                                                                      [JrdDatamanager manager].user.userId,
                                                                                      [CourseAvaListArray[i]  valueForKey:@"course_id"],
                                                                                      [CourseAvaListArray[i]  valueForKey:@"course"],
                                                                                      [CourseAvaListArray[i]  valueForKey:@"description"],
                                                                                      @"selectd",
                                                                                      startDate_v,
                                                                                      endDate_v,
                                                                                      [CourseAvaListArray[i]  valueForKey:@"icon_url"],
                                                                                      @(0), //0 not, 1 selected, 2 download
                                                                                      @(0),
                                                                                      @""
                                                                                      ]];
                    NSLog(@"ret = %d", ret);
                }else{
                    //update database
                    NSString * searchCondition1 = [NSString stringWithFormat:@"course_id=%@ and user_id=%@",arraySearch[0][COURSE_ID],[JrdDatamanager manager].user.userId];
                    
                    Boolean ret = [manager updateDataToSheet_CourseList:@"courselist" withData:@[
                                                                                                 [CourseAvaListArray[i]  valueForKey:@"course"],
                                                                                                 [CourseAvaListArray[i]  valueForKey:@"description"],
                                                                                                 @"selectd",
                                                                                                 startDate_v,
                                                                                                 endDate_v,
                                                                                                 [CourseAvaListArray[i]  valueForKey:@"icon_url"],
                                                                                                 ] where:searchCondition1];
                    NSLog(@"ret = %d", ret);
                    
                }
            }
            [[NSNotificationCenter defaultCenter] postNotificationName:kSelectCourseNotification object:self];
        }
        [weakself.tableView reloadData];
        [weakself.tableView.mj_header endRefreshing];
        [weakself.tableView.mj_footer endRefreshing];
    } failure:^(NSError *erro) {
        
    } showHUD:nil];

}

#pragma mark - set table

-(void)configureTable{
    int table_y = _cycleScrollView.frame.origin.y + _cycleScrollView.frame.size.height;
    
    self.tableView                 = [[UITableView alloc] initWithFrame:CGRectMake(0, table_y, SCREEN_WIDTH, SCREEN_HEIGHT - table_y) style:UITableViewStylePlain];
    //self.tableView.style = UITableViewStylePlain;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self setupTableview];
}

- (void)loadNewData{
    _page = 1;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self getCourseData];
        //[self reloadDataUpdate];
    });

}

- (void)loadMoreData{
    _page++;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self getCourseData];
    });
    
}

-(void)setupTableview{
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    //设置普通状态的动画图片
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=60; ++i) {
        //        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"dropdown_anim__000%zd",i]];
        //        [idleImages addObject:image];
        UIImage *image = [UIImage imageNamed:@"icon_listheader_animation_1"];
        [idleImages addObject:image];
    }
    [header setImages:idleImages forState:MJRefreshStateIdle];
    
    //设置即将刷新状态的动画图片
    NSMutableArray *refreshingImages = [NSMutableArray array];
    UIImage *image1 = [UIImage imageNamed:@"icon_listheader_animation_1"];
    [refreshingImages addObject:image1];
    UIImage *image2 = [UIImage imageNamed:@"icon_listheader_animation_2"];
    [refreshingImages addObject:image2];
    [header setImages:refreshingImages forState:MJRefreshStatePulling];
    [header setImages:refreshingImages forState:MJRefreshStateRefreshing];

    self.tableView.mj_header = header;
    //马上进入刷新状态
    //[self.tableView.mj_header beginRefreshing];
    
    //上拉刷新
    //self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
}

#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(0 == courseSel.count){
        return 1;
    }else{
        return courseSel.count;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return JRD_COURSE_TABLE_H;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIndentifier = @"courseCell2";
    JRDCourseCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[JRDCourseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
        //下划线
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 71.5, SCREEN_WIDTH, 0.5)];
        lineView.backgroundColor = JRD_RGB(200, 199, 204);
        [cell addSubview:lineView];
    }
    if(0 == courseSel.count){
        cell.textLabel.text=NSLocalizedString(@"jrd_select_course", nil);//@"Pls select course at course center.";
        return cell;
    }
    JrdCourseModel *jrdCourseM = [[JrdCourseModel alloc] init];
    jrdCourseM.courseName = courseSel[indexPath.row][COURSE_NAME];
    jrdCourseM.courseDes = [NSString stringWithFormat:@"%@ ~ %@",courseSel[indexPath.row][COURSE_STARTDATE],courseSel[indexPath.row][COURSE_ENDDATE]];
    NSString* url_icon = courseSel[indexPath.row][COURSE_ICON_URL];//[courseSel[indexPath.row] valueForKey:@"icon_url"];
    jrdCourseM.coursePhoto = [NSString stringWithFormat:@"http://120.55.86.220/%@",url_icon];
    [cell setJzCourseM:jrdCourseM];
    // calc the study percent
    NSString * searchCondition = [NSString stringWithFormat:@"node_parentid=%@ and user_id=%@",
                            courseSel[indexPath.row][COURSE_ID],[JrdDatamanager manager].user.userId];
    NSArray* array = [manager searchDataFromSheet:@"nodelist" where:searchCondition];
    float per_cent = (float)1/array.count;
    float total_cent =0;
    if(nil!= array && 0!=array.count)
    {
        float  toatal_time = 0;
        float  study_time = 0;
        for(int i = 0; i < array.count; i++){
            NSString* total = array[i][NODE_TOTAL_TIME];
            NSString* study = array[i][NODE_STUDY_TIME];
            toatal_time = [total floatValue];
            study_time = [study floatValue];
            if(0 != study_time){
                total_cent+=study_time*100/toatal_time*per_cent;
            }
        }
        [cell setPercent:total_cent];
    }else{
        [cell setPercent:0];
    }
    //check the current date
    NSDate * senddate=[NSDate date];

    //start date
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    [dateformatter setTimeZone:zone];
    //NSDate * startDate=[dateformatter dateFromString:courseSel[indexPath.row][COURSE_STARTDATE]];
    NSDate * endDate=[dateformatter dateFromString:courseSel[indexPath.row][COURSE_ENDDATE]];
    /*NSComparisonResult result = [senddate compare:startDate];
    BOOL ret = false;
    if(NSOrderedDescending == result){
        NSComparisonResult result_ext = [endDate compare:senddate];
        if(NSOrderedDescending == result_ext){
            ret = true;
        }
    }*/
    BOOL ret = false;

    NSComparisonResult result_ext = [endDate compare:senddate];
    if(NSOrderedDescending == result_ext){
        ret = true;
    }

    if(JRD_CHECK_VALUE == [[JrdDatamanager manager] getCheckValue]){
    
    }else{
        if(false == ret){
            //已过期
            cell.backgroundColor = JrdGrayColor;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
    }
    return cell;
}


#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    JRDCourseCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if(JRD_CHECK_VALUE== [[JrdDatamanager manager] getCheckValue]){
    
    }else{
        if(UITableViewCellSelectionStyleNone == cell.selectionStyle){
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"" message:NSLocalizedString(@"Jrd_expired", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"jrd_OK", nil) otherButtonTitles:nil , nil];
            [alertView show];
            return;
        }
    }
    if(0 == courseSel.count){
        return;
    }
    NSLog(@"didselect row ");
    JrdCourseModel* jrdCoursmodel = [[JrdCourseModel alloc] init];
    jrdCoursmodel.courseName = courseSel[indexPath.row][COURSE_NAME];//[courseSel[indexPath.row] valueForKey:@"course"];
    jrdCoursmodel.courseDes =courseSel[indexPath.row][COURSE_DES];//[courseSel[indexPath.row] valueForKey:@"course"];
    NSString* url_icon = courseSel[indexPath.row][COURSE_ICON_URL];//[courseSel[indexPath.row] valueForKey:@"icon_url"];
    jrdCoursmodel.coursePhoto = [NSString stringWithFormat:@"http://120.55.86.220/%@",url_icon];
    jrdCoursmodel.courseId = courseSel[indexPath.row][COURSE_ID];//[courseSel[indexPath.row]  valueForKey:@"course_id"];
    jrdCoursmodel.courseStartTime =courseSel[indexPath.row][COURSE_STARTDATE];//[courseSel[indexPath.row]  valueForKey:@"startDate"];
    jrdCoursmodel.courseEndTime =courseSel[indexPath.row][COURSE_ENDDATE];//[courseSel[indexPath.row]  valueForKey:@"endDate"];
    JrdCourseDetailViewController* vc = [[JrdCourseDetailViewController alloc] init];
    vc.coursemodel = jrdCoursmodel;
    vc.enter_type = ENTER_FROM_NORMAL;
    [self.navigationController pushViewController:vc animated:YES];
    return;
}

#pragma mark - Mark data
- (NSMutableArray *)songArray
{
    if (!_songArray) {
        _songArray = [NSMutableArray array];
    }
    return _songArray;
}

-(void)dataJson
{
    NSString *str = [[NSBundle mainBundle]pathForResource:@"musicPaper" ofType:@"json"];
    NSData *data = [[NSData alloc]initWithContentsOfFile:str];
    
    NSMutableArray *dataArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@,  ---%ld",dataArray, (unsigned long)dataArray.count);
    //    [self.songArray addObject:dic];
    for (NSDictionary *dic in dataArray) {
        MusicModel *model = [[MusicModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [self.songArray addObject:model];
    }
    //[self.songTableView reloadData];
}

@end
